"""小牛快快长大"""
import random
from datetime import date, timedelta
from threading import Thread
import cow
import grass
import log_util


def cow_grow():
    """
    小牛的成长记录
    :return:
    """
    beg_date = date(2020, 5, 1)
    end_date = beg_date + timedelta(days=30)
    grass_lst = []  # 定义50颗小草
    cow_lst = []  # 定义10头牛
    # 初始化草和牛
    log_util.log("初始化50颗草对象")
    for i in range(0, 50):
        grass_temp = grass.Grass(i)
        grass_lst.append(grass_temp)

    log_util.log("初始化10头小牛对象")
    for i in range(0, 10):
        cow_temp = cow.Cow(i, "小牛" + str(i) + "号", "M" if i % 2 == 0 else "W")
        cow_lst.append(cow_temp)

    print(len(grass_lst))

    while beg_date <= end_date:
        log_util.log("今天是{}".format(beg_date.strftime("%Y-%m-%d")))
        beg_date += timedelta(days=1)

        # 判断小草是否生长
        if is_rain():
            log_util.log("今天是个下雨天，小草要生长")
            for i in range(len(grass_lst) - 1):
                print("小草编号{}".format(grass_lst[i].grass_no))
                grass_lst[i] = grass_lst[i].grass_grow()
        else:
            log_util.log("今天不是下雨天，小草不生长")
            continue

        # 不管下不下雨，小牛都要吃草


    # 打印小草目前的生长情况
    for grass_item in grass_lst:
        print("小草{},成长次数：{}".format(grass_item.grass_no, grass_item.grass_age))


def is_rain():
    """
    判断今天是否下雨
    :return:
    """
    if random.randint(1, 100) <= 20:
        # 今天是下雨天
        return True
    else:
        return False


if __name__ == "__main__":
    cow_grow()
